package tool

import tool.Pojo.MissionData

import java.io.File
import scala.collection.mutable
import implicits.Implicits._
import org.apache.commons.io.FileUtils
import shared.Pojo._
import utils.Utils
import upickle.default._
import models.Tables._

/**
 * Created by yz on 26/9/2021
 */
trait ProjectTool {

  def getSeqMap(file: File) = {
    val map = mutable.LinkedHashMap[String, String]()
    var key = ""
    file.lines.foreach { line =>
      if (line.startsWith(">")) {
        key = line
        map += (key -> "")
      } else if (key != "") {
        map(key) += line
      }
    }
    map
  }

  def getDbFile(againstType: String) = {
    againstType match {
      case "macadamiaGene" => new File(Tool.seqsDir, "macadamia.cds.fa")
      case "macadamiaGenome" => new File(Tool.seqsDir, "macadamia.genome.fa")
      case "mintegChloroplastGenome" => new File(Tool.seqsDir, "minteg_chloroplast.fa")
      case "mintegMitochondrionGenome" => new File(Tool.seqsDir, "minteg_mitochondrion.fa")
      case "minteg2022Genome" => new File(Tool.seqsDir, "minteg_2022.genome.fa")
      case "macadamiaPep" => new File(Tool.seqsDir, "macadamia.pep.fa")
      case "mjanseniGenome" => new File(Tool.seqsDir, "mjanseni.fa")
      case "mtetraGenome" => new File(Tool.seqsDir, "mtetra.fa")
      case "mtetraPlastidGenome" => new File(Tool.seqsDir, "mtetra_plastid.fa")
      case "mtetraMitochondrionGenome" => new File(Tool.seqsDir, "mtetra_mitochondrion.fa")
      case "mterniGenome" => new File(Tool.seqsDir, "mterni.fa")
      case "mterniPlastidGenome" => new File(Tool.seqsDir, "mterni_plastid.fa")
      case "mterniMitochondrionGenome" => new File(Tool.seqsDir, "mterni_mitochondrion.fa")
    }
  }

  def getGenomeFile(species: String) = {
    species match {
      case "Macadamia integrifolia" => new File(Tool.seqsDir, "macadamia.genome.fa")
    }
  }

  def dealInputFile(file: File) = {
    val lines = file.lines
    val newLines = lines.map(_.trim)
    newLines.toFile(file)
  }

}
